﻿using System.Windows;
using Blake.NUI.WPF.Gestures;
using Microsoft.Surface.Presentation.Controls;
using MTBrainStorm.Multitouch.Input;
using MTBrainStorm.ViewModels;

namespace MTBrainStorm
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : SurfaceWindow
    {
        public MainWindow()
        {
            InitializeComponent();
            Events.RegisterGestureEventSupport(this);
            InputProviderManager.RegisterEvents(this, InputProviders.Mouse);
            InputProviderManager.RegisterEvents(this, InputProviders.Tuio);
        }


        private void ContainerManipulationCompleted(object sender, ContainerManipulationCompletedEventArgs e)
        {
            var svi = (ScatterViewItem)e.OriginalSource;
            var trashBounds = trash.TransformToVisual(this).TransformBounds(new Rect(0, 0, trash.ActualWidth, trash.ActualHeight));
            var trash2Bounds = trash2.TransformToVisual(this).TransformBounds(new Rect(0, 0, trash2.ActualWidth, trash2.ActualHeight));
            var sviBounds = new Rect(svi.Center.X - .25 * svi.ActualWidth, svi.Center.Y - .25 * svi.ActualHeight, .5 * svi.ActualWidth, .5 * svi.ActualHeight);

            if (sviBounds.IntersectsWith(trashBounds) || sviBounds.IntersectsWith(trash2Bounds))
                ((MainWindowViewModel)DataContext).RemoveNode.Execute(svi.DataContext);

        }
    }
}
